<?php
// +----------------------------------------------------------------------
// | INPHP
// | Copyright (c) https://inphp.cc All rights reserved.
// | 该文件源码由INPHP官方提供，使用协议以INPHP官方公告为准。
// +----------------------------------------------------------------------
// | 聚合列表页面，可用于搜索结果列表、标签内容列表、分类列表
// +----------------------------------------------------------------------
namespace app\cms\http\web;

use app\cms\tags\archiveList;
use Inphp\Core\Context;
use Inphp\Core\Util\Str;

class search extends controller
{
    public function index()
    {
        //设置当前展示页面类型
        Context::set("CMS_PAGE", "search");
        $keyword = GET("keyword");
        $keyword = !empty($keyword) ? Str::trim($keyword) : null;
        //列表、分页
        $page = GET("page", 1);
        $page = is_numeric($page) && $page > 0 ? ceil($page) : 1;
        $total = GET("total", 30);
        $total = is_numeric($total) && $total > 0 ? ceil($total) : 30;
        $total = min($total, 100);
        $list = archiveList::process([
            "keyword"       => $keyword,
            "page"          => $page,
            "total"         => $total,
            "pager"         => true
        ]);
        viewAssign("list", $list);
        viewAssign("CMS_PAGE_TITLE", !empty($keyword) ? $keyword : "搜索文章");
        viewAssign("CMS_PAGE_SEARCH_KEYWORD", !empty($keyword) ? $keyword : "");
    }
}